<template>
  <el-cascader
    :options="options"
    :props="props"
    @change="change"
    v-model="selectIds"
    clearable></el-cascader>
</template>

<script>
  import {getTreeByParent} from '@/api/orgInfo'
  import {getParentOrgIds} from '@/api/research'
  export default {
      name: "index",
      model: {
        prop: 'orgId',
        event: 'cc'
      },
      props:["orgId"],
      data() {
        return {
          props:{
            checkStrictly: true,
            value: 'id',
            label: 'label',
            children: 'children',
          },
          options: [],
          selectIds:[]
        }
      },
      mounted() {
        let _this = this;
        getTreeByParent("-1").then(function (data) {
          if (data.code == 200){
            _this.options = data.data[0].children;
          } else{
            _this.$message.error(data.message);
          }
        })
        _this.initOrgIds(this.orgId);
      },
      methods : {
        updateParentVal(val){
          this.$emit('cc', val)
        },
        change(val){
          this.updateParentVal(val[val.length-1]);
        },
        initOrgIds(val){
          let _this = this;
          getParentOrgIds(val).then(function (data) {
            if (data.code == 200){
              _this.selectIds = data.data;
            } else{
              _this.$message.error(data.message);
            }
          })
        }
      }
  }
</script>

<style scoped>

</style>
